---
sidebar_label: Google Vertex AI
keywords: [gemini, gemini-pro, ChatVertexAI, vertex]
---

import CodeBlock from "@theme/CodeBlock";

# ChatVertexAI

LangChain.js supports Google Vertex AI chat models as an integration.
It supports two different methods of authentication based on whether you're running
in a Node environment or a web environment.

## Setup

### Node

To call Vertex AI models in Node, you'll need to install the `@langchain/google-vertexai` package:

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/google-vertexai
```

import UnifiedModelParamsTooltip from "@mdx_components/unified_model_params_tooltip.mdx";

<UnifiedModelParamsTooltip></UnifiedModelParamsTooltip>

You should make sure the Vertex AI API is
enabled for the relevant project and that you've authenticated to
Google Cloud using one of these methods:

- You are logged into an account (using `gcloud auth application-default login`)
  permitted to that project.
- You are running on a machine using a service account that is permitted
  to the project.
- You have downloaded the credentials for a service account that is permitted
  to the project and set the `GOOGLE_APPLICATION_CREDENTIALS` environment
  variable to the path of this file.

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/google-vertexai
```

### Web

To call Vertex AI models in web environments (like Edge functions), you'll need to install
the `@langchain/google-vertexai-web` package:

```bash npm2yarn
npm install @langchain/google-vertexai-web
```

Then, you'll need to add your service account credentials directly as a `GOOGLE_VERTEX_AI_WEB_CREDENTIALS` environment variable:

```
GOOGLE_VERTEX_AI_WEB_CREDENTIALS={"type":"service_account","project_id":"YOUR_PROJECT-12345",...}
```

Lastly, you may also pass your credentials directly in code like this:

```typescript
import { ChatVertexAI } from "@langchain/google-vertexai-web";

const model = new ChatVertexAI({
  authOptions: {
    credentials: {"type":"service_account","project_id":"YOUR_PROJECT-12345",...},
  },
});
```

## Usage

The entire family of `gemini` models are available by specifying the `modelName` parameter.

For example:

import ChatVertexAI from "@examples/models/chat/integration_googlevertexai.ts";

<CodeBlock language="typescript">{ChatVertexAI}</CodeBlock>

:::tip
See the LangSmith trace for the example above [here](https://smith.langchain.com/public/9fb579d8-4987-4302-beca-29a684ae2f4c/r).
:::

### Streaming

`ChatVertexAI` also supports streaming in multiple chunks for faster responses:

import ChatVertexAIStreaming from "@examples/models/chat/integration_googlevertexai-streaming.ts";

<CodeBlock language="typescript">{ChatVertexAIStreaming}</CodeBlock>

:::tip
See the LangSmith trace for the example above [here](https://smith.langchain.com/public/ba4cb190-3f60-49aa-a6f8-7d31316d94cf/r).
:::

### Tool calling

`ChatVertexAI` also supports calling the model with a tool:

import ChatVertexAITool from "@examples/models/chat/integration_googlevertexai-tools.ts";

<CodeBlock language="typescript">{ChatVertexAITool}</CodeBlock>

:::tip
See the LangSmith trace for the example above [here](https://smith.langchain.com/public/49e1c32c-395a-45e2-afba-913aa3389137/r).
:::

### `withStructuredOutput`

Alternatively, you can also use the `withStructuredOutput` method:

import ChatVertexAIWSA from "@examples/models/chat/integration_googlevertexai-wsa.ts";

<CodeBlock language="typescript">{ChatVertexAIWSA}</CodeBlock>

:::tip
See the LangSmith trace for the example above [here](https://smith.langchain.com/public/41bbbddb-f357-4bfa-a111-def8294a4514/r).
:::

### VertexAI tools agent

The Gemini family of models not only support tool calling, but can also be used in the Tool Calling agent.
Here's an example:

import AgentsExample from "@examples/models/chat/chat_vertexai_agents.ts";

<CodeBlock language="typescript">{AgentsExample}</CodeBlock>

:::tip
See the LangSmith trace for the agent example above [here](https://smith.langchain.com/public/5615ee35-ba76-433b-8639-9b321cb6d4bf/r).
:::
